package name.zxw.rabbitmq.util;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author ZhangXinWang
 * @date 2022/5/18 20:01
 */
public class RabbitMqUtils {

    private static String HOST = "127.0.0.1";
    private static String USER_NAME = "guest";
    private static String PASSWORD = "guest";


    public static Channel getChannel() throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        //默认之就是localhost,我这边正好装在了本地,可以省略
//        factory.setHost(HOST);
        factory.setUsername(USER_NAME);
        factory.setPassword(PASSWORD);
        Connection connection = factory.newConnection();
        return connection.createChannel();

    }
}
